package com.tmeone.erpone.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tmeone.erpone.entity.JsonResult;
import com.tmeone.erpone.entity.TOrder1;
import com.tmeone.erpone.entity.TProductionLine;
import com.tmeone.erpone.service.IScDscService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ScDscController {
    @Autowired
    private IScDscService iScDscService;
    @RequestMapping("/sc_dsc")
    public JsonResult select(@RequestParam(value = "current",required = false,defaultValue = "1")Integer current,
                             @RequestParam(value = "pageSize",required = false,defaultValue = "5")Integer pageSize){
        Page<TOrder1> page = new Page<>(current, pageSize);
        IPage<TOrder1> iPage = iScDscService.selectPage(page);
        return new JsonResult(1,iPage);
    }
    @RequestMapping("/sc_dscOrderStatus")
    public JsonResult selectStatus(){
        List<TOrder1> tOrder1s = iScDscService.selectStatus();
        return new JsonResult(1, tOrder1s);
    }
    @PostMapping("/selectOrderByIds")
    public JsonResult selectOrderByIds(@RequestBody TOrder1 tOrders1){
        System.out.println(tOrders1.getCurrent()+"_____"+ tOrders1.getPageSize());
        Page<TOrder1> page = new Page<>(1, tOrders1.getPageSize());
        IPage<TOrder1> iPage = iScDscService.selectPageById(page, tOrders1.getOrderId(), tOrders1.getProductStatus());
       /* List<TOrder> list = iScDscService.list(new QueryWrapper<TOrder>()
                                .lambda().
                                eq(TOrder::getOrderId,tOrders.getOrderId()).
                                eq(TOrder::getProductStatus, tOrders.getProductStatus())
                                );
        iPage.setRecords(list);*/
        return new JsonResult(1,iPage);
    }

    @PutMapping("/sc_dsc")
    public JsonResult update(@RequestBody TOrder1 order){
        order.setLaserCode("1");
        iScDscService.updateLaserCode(order.getLaserCode(),order.getOrderId());
        return new JsonResult(1,null);
    }

    @RequestMapping("/productLine")
    public JsonResult productLine(){
        List<TProductionLine> tProductionLines = iScDscService.selectProductLine();
        return new JsonResult(1,tProductionLines);
    }
    @RequestMapping("/printer")
    public JsonResult printer(){
        List<TOrder1> orders = iScDscService.selectPrinter();
        return new JsonResult(1,orders);
    }

}
